<%--

    Copyright (C) 2007-2011 JUG Events Team <info@jugevents.org>

    This file is part of JUG Events Web Application.

    Licensed under the Apache License, Version 2.0 (the "License");
    you may not use this file except in compliance with the License.
    You may obtain a copy of the License at

     http://www.apache.org/licenses/LICENSE-2.0

    Unless required by applicable law or agreed to in writing, software
    distributed under the License is distributed on an "AS IS" BASIS,
    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    See the License for the specific language governing permissions and
    limitations under the License.

--%>

<%@ include file="../common.jspf" %>
<%@page import="it.jugpadova.util.Utilities"%>
<jwr:script src="${cp}/dwr/interface/juggerBo.js" />
<jwr:script src="${cp}/dwr/interface/AjaxMethodsJS.js" />
<jwr:script src="/javascripts/modal.js" />
<style type="text/css">

    #mww
    {
        position: fixed;    
        z-index: 10;
        background-color: white;
        display: none;
        width: 	18em;
        height: 10em;
        border: 2px solid blue;
        padding: 2em 2em 2em 2em;	

    }

    #mbg
    {
        position: fixed;
        left: 0;
        top: 0;
        width: 100%;
        height: 100%;

        z-index: 9;
        background-color:#222222;
        display: none;
        opacity: 0.50;
        filter: alpha(opacity=40);
    }
</style>

<!--[if gte IE 5.5]>
<![if lt IE 7]>
<style>
#mbg, #modalIframe
{    
        position: absolute;
    left: expression(ignoreMe = document.documentElement.scrollLeft + "px");
    top: expression(ignoreMe = document.documentElement.scrollTop + "px");
    width: expression(document.documentElement.clientWidth + "px");
    height: expression(document.documentElement.clientHeight + "px");
}

#modalIframe
{
        filter: alpha(opacity=0);
        z-index: 8;
}

#mww
{
        position: absolute;
    left: expression(ignoreMe = document.documentElement.scrollLeft + "px");
    top: expression(ignoreMe = document.documentElement.scrollTop + "px");
}
</style>
<![endif]>
<![endif]-->

<h1><spring:message code="Edit-Jugger"/></h1>

<%@ include file="../message.jspf" %>

<form:form commandName="jugger" method="post" action="${cp}/jugger/edit.form" enctype="multipart/form-data">
    <form:errors path="*" cssClass="errorBox"/>                                                                        
    <fieldset>
        <legend>Jugger</legend>
        <form:hidden path="jugger.user.username"/>
        <form:hidden path="reliable" />                            
        <dl>
            <dt><form:label path="jugger.firstName"><spring:message code="juggerRegistrationFirstName"/> (*)</form:label></dt>
            <dd><form:input path="jugger.firstName"/></dd>
            <dt><form:label path="jugger.lastName"><spring:message code="juggerRegistrationLastName"/> (*)</form:label></dt>
            <dd><form:input path="jugger.lastName"/></dd>
            <dt><form:label path="jugger.email"><spring:message code="Email"/> (*)</form:label></dt>
            <dd><form:input path="jugger.email" size="35"/></dd>
            <dt><form:label path="password"><spring:message code="password"/></form:label></dt>
            <dd><form:password path="password" /></dd>
            <dt><form:label path="confirmPassword"><spring:message code="confirmPassword"/></form:label></dt>
            <dd><form:password path="confirmPassword" /></dd>

        </dl>
    </fieldset>


    <security:authorize ifAnyGranted="ROLE_JUGGER">    
        
    </security:authorize>



    <fieldset><legend>JUG</legend>
        <span id="jugLogo"><img style="float: right;" src="${cp}/bin/jugLogo.bin?id=${jugger.jugger.jug.id}" alt="JUG Logo" width="100"/></span>
        <dl>
            <dt><form:label path="jugger.jug.name">
                    <spring:message code="juggerRegistrationJUGName" /> (*)</form:label></dt>
            <dd><form:input path="jugger.jug.name" 
                        onblur="javascript:disableJugFields();" />
                <div id="jugList" class="auto_complete"></div>
            </dd>
            <dt><form:label path="jugger.jug.internalFriendlyName">
                    <spring:message code="juggerRegistrationJUGFriendlyName" text="?juggerRegistrationJUGFriendlyName?" /></form:label></dt>
            <dd><form:input path="jugger.jug.internalFriendlyName" readonly="${!jugger.reliable}" disabled="${!jugger.reliable}"/>
            </dd>
            <div id="friendlyUrlsDiv" class="smallText form-aligned">
                <b><spring:message code="FriendlyUrls" text="?FriendlyUrls?"/>:</b><br/>
                <div id="friendlyUrls"> <!-- AJAX filled --> </div>
            </div>
            <dt><form:label path="jugger.jug.country.englishName">
                    <spring:message code="juggerRegistrationCountry" />
                </form:label></dt>
            <dd><form:input path="jugger.jug.country.englishName" readonly="${!jugger.reliable}" disabled="${!jugger.reliable}" />
                <div id="countryList" class="auto_complete"></div>
            </dd>
            <dt><form:label path="jugger.jug.webSite">
                    <spring:message code="juggerRegistrationWebSite" />
                </form:label></dt>
            <dd><form:input path="jugger.jug.webSite" readonly="${!jugger.reliable}" disabled="${!jugger.reliable}"/></dd>
            <dt><form:label path="jugger.jug.logo">
                    <img id="tip_jugLogo" src="${cp}/images/question16x16.png" alt="Help Tip"/>&nbsp;<spring:message code="juggerRegistrationLogo" />
                </form:label></dt>
            <dd><input type="file" name="jugger.jug.logo" id="jugger.jug.logo"  <c:if test="${!jugger.reliable}">readonly="readonly" disabled="disabled"</c:if>/></dd>
            <dt><form:label path="jugger.jug.longitude">
                    <img id="tip_jugCoordinates" src="${cp}/images/question16x16.png" alt="Help Tip"/>&nbsp;<spring:message code="juggerRegistrationLongitude" />
                </form:label></dt>
            <dd>
                <form:input path="jugger.jug.longitude" readonly="${!jugger.reliable}" disabled="${!jugger.reliable}"/><br/>
                <a href="http://www.travelgis.com/geocode/" rel="external" class="smallText"><spring:message code="FindYourLocation" text="Find Your Location"/></a>
            </dd>
            <dt><form:label path="jugger.jug.latitude">
                    <spring:message code="juggerRegistrationLatitude" />
                </form:label></dt>
            <dd><form:input path="jugger.jug.latitude" readonly="${!jugger.reliable}" disabled="${!jugger.reliable}"/></dd>
            <dt><form:label path="jugger.jug.timeZoneId">
                    <spring:message code="juggerRegistrationTimezone" />
                </form:label></dt>
            <dd><form:select items="${timezones}" itemLabel="description" itemValue="id"  path="jugger.jug.timeZoneId" disabled="${!jugger.reliable}"/></dd>
            <dt><form:label path="jugger.jug.contactName">
                    <spring:message code="juggerRegistrationContactName" />
                </form:label></dt>
            <dd><form:input path="jugger.jug.contactName" readonly="${!jugger.reliable}" disabled="${!jugger.reliable}"/></dd>
            <dt><form:label path="jugger.jug.contactEmail">
                    <spring:message code="juggerRegistrationContactEmail" />
                </form:label></dt>
            <dd><form:input path="jugger.jug.contactEmail" readonly="${!jugger.reliable}" disabled="${!jugger.reliable}"/></dd>
            <dt><form:label path="jugger.jug.certificateTemplate">
                    <img id="tip_jugCertificateTemplate" src="${cp}/images/question16x16.png" alt="Help Tip"/>&nbsp;<spring:message code="juggerRegistrationCertificateTemplate" />
                </form:label></dt>
            <dd>
                <input type="file" name="jugger.jug.certificateTemplate" id="jugger.jug.certificateTemplate"  <c:if test="${!jugger.reliable}">readonly="readonly" disabled="disabled"</c:if>/><br/>
                <a href="${cp}/docs/certificate.odt" class="smallText"><spring:message code="Example"/></a>
                <a href="${cp}/bin/jugCertificatePreview.bin?id=${jugger.jugger.jug.id}" class="smallText"><spring:message code="Preview"/></a>                                    
            </dd>
            <dt><form:label path="jugger.jug.infos">
                    <spring:message code="juggerRegistrationJUGInfos" />
                </form:label></dt>
            <dd><form:textarea path="jugger.jug.infos" cols="30" rows="5" readonly="${!jugger.reliable}" disabled="${!jugger.reliable}"/></dd>
        </dl>
    </fieldset>
    <dl>
        <dt>&nbsp;</dt>
        <dd><input type="submit" value="<spring:message code='Update'/>" /><br/><br/></dd>                            
        <dt><spring:message code="juggerRegistrationRequired" /> (*)</dt><dd>&nbsp;</dd>                            
    </dl>

</form:form>

<div id="mww">    
    
</div>
<div id="mbg"></div>

<script type="text/javascript">

    new Tip($('tip_jugLogo'), '<spring:message code="tip.jugLogo"/>', {title: '<spring:message code="tip.jugLogo.title"/>', effect: 'appear'});
    new Tip($('tip_jugCertificateTemplate'), '<spring:message code="tip.jugCertificateTemplate"/>', {title: '<spring:message code="tip.jugCertificateTemplate.title"/>', effect: 'appear'});
    new Tip($('tip_jugCoordinates'), '<spring:message code="tip.jugCoordinates"/>', {title: '<spring:message code="tip.jugCoordinates.title"/>', effect: 'appear'});

    dwr.util.setEscapeHtml(false);
            
    new Autocompleter.DWR('jugger.jug.country.englishName', 'countryList', updateCountryList, { valueSelector: singleValueSelector, partialChars: 0, fullSearch: true });
    new Autocompleter.DWR('jugger.jug.name', 'jugList', updateJUGNameList, { valueSelector: singleValueSelector, partialChars: 0, fullSearch: true, afterUpdateElement: populateJugFields });

    juggerBo.updateFriendlyUrls($F('jugger.jug.name'), $F('jugger.jug.internalFriendlyName'));

    new Form.Element.Observer('jugger.jug.internalFriendlyName', 1,
    function(el, value) {
        juggerBo.updateFriendlyUrls($F('jugger.jug.name'), $F('jugger.jug.internalFriendlyName'));
    });

    function updateCountryList(autocompleter, token) {
        juggerBo.findPartialCountry(token, function(data) {
            autocompleter.setChoices(data)
        });
    }
            
    function updateJUGNameList(autocompleter, token) {
        juggerBo.findPartialJugNameWithCountry(token, $('jugger.jug.country.englishName').value, function(data) {
            autocompleter.setChoices(data)
        });
    }
            
    function populateJugFields(jugName, selectedElement) {
        juggerBo.populateJugFields(jugName.value);
    }
            
    function singleValueSelector(tag) {
        return tag;
    }
            
    function disableJugFields() {
        // var s = document.getElementById('jugger.jug.name');      
        // var k = document.getElementById('reliable');    
       
    }
            
   
</script>
